package treeHoleUI;

import treeHoleSERVICE.Landing;
import treeHoleSERVICE.LandingIMPH;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

/**
 * @program:IntelliJ IDEA
 * @Description: 登陆页面
 * @author: Mr.zheng
 * @data: 2022/6/16 10:16
 */
public class LoginInterface extends JFrame {
    private static int userAccount1;

    public int getUserAccount1() {
        return userAccount1;
    }

    private void setUserAccount1(int userAccount1) {
        this.userAccount1 = userAccount1;
    }

    public LoginInterface() {
        initComponents();
    }

    private void turn_to_hole(ActionEvent e) {
        // TODO add your code here
        Landing landingIMPH=new LandingIMPH();
        String id = textField1.getText();
        int id1=Integer.parseInt(id);
        String pass= String.valueOf(passwordField1.getPassword());
        boolean landingResult = landingIMPH.landing(id1, pass);
        if (!landingResult) {
            JOptionPane.showMessageDialog(this,"密码错误","tips",JOptionPane.INFORMATION_MESSAGE);
        }
        else {
            this.setUserAccount1(id1);
            this.dispose();
            new TreeHoleInterface().setVisible(true);
        }

    }


    private void turn_down(MouseEvent e) {
        // TODO add your code here
        this.dispose();
    }


    private void turn_to_register(MouseEvent e) {
        // TODO add your code here
        new RegistrationPage().setVisible(true);
        this.dispose();
    }

    private void thisMouseClicked(MouseEvent e) {
        // TODO add your code here
        this.dispose();
    }

    private void thisWindowClosed(WindowEvent e) {
        // TODO add your code here
        this.dispose();
    }

    private void initComponents() {

        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
        panel1 = new JPanel();
        passwordField1 = new JPasswordField();
        textField1 = new JTextField();
        panel2 = new JPanel();
        label1 = new JLabel();
        panel3 = new JPanel();
        button1 = new JButton();
        button2 = new JButton();
        panel4 = new JPanel();
        label2 = new JLabel();
        label3 = new JLabel();
        panel5 = new JPanel();
        button3 = new JButton();

        //======== this ========
        {
            this.setLayout(new BorderLayout());

            //======== panel1 ========
            {
                panel1.setLayout(new BorderLayout());

                //---- passwordField1 ----
                passwordField1.setHorizontalAlignment(SwingConstants.LEFT);
                panel1.add(passwordField1, BorderLayout.SOUTH);

                //---- textField1 ----
                textField1.setHorizontalAlignment(SwingConstants.LEFT);
                panel1.add(textField1, BorderLayout.NORTH);
            }
            this.add(panel1, BorderLayout.CENTER);

            //======== panel2 ========
            {
                panel2.setLayout(new BorderLayout());

                //---- label1 ----
                label1.setText("\u6811\u6d1e\u9879\u76ee");
                label1.setHorizontalAlignment(SwingConstants.CENTER);
                label1.setFont(label1.getFont().deriveFont(label1.getFont().getSize() + 30f));
                panel2.add(label1, BorderLayout.PAGE_START);
            }
            this.add(panel2, BorderLayout.NORTH);

            //======== panel3 ========
            {
                panel3.setLayout(new FlowLayout());

                //---- button1 ----
                button1.setText("\u767b\u5f55");
                button1.addActionListener(e -> turn_to_hole(e));
                panel3.add(button1);

                //---- button2 ----
                button2.setText("\u53d6\u6d88");
                button2.addMouseListener(new MouseAdapter() {
                    @Override
                    public void mouseClicked(MouseEvent e) {
                        turn_down(e);
                    }
                });
                panel3.add(button2);
            }
            this.add(panel3, BorderLayout.SOUTH);

            //======== panel4 ========
            {
                panel4.setLayout(new GridLayout(2, 1));

                //---- label2 ----
                label2.setText("\u7528\u6237\u540d");
                panel4.add(label2);

                //---- label3 ----
                label3.setText("\u5bc6\u7801");
                panel4.add(label3);
            }
            this.add(panel4, BorderLayout.WEST);

            //======== panel5 ========
            {
                panel5.setLayout(new BorderLayout());

                //---- button3 ----
                button3.setText("\u6ce8\u518c");
                button3.addMouseListener(new MouseAdapter() {
                    @Override
                    public void mouseClicked(MouseEvent e) {
                        turn_to_register(e);
                    }
                });
                panel5.add(button3, BorderLayout.CENTER);
            }
            this.add(panel5, BorderLayout.EAST);
            this.pack();
            this.setLocationRelativeTo(this.getOwner());
            setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        }
        // JFormDesigner - End of component initialization  //GEN-END:initComponents

    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
    private JPanel panel1;
    private JPasswordField passwordField1;
    private JTextField textField1;
    private JPanel panel2;
    private JLabel label1;
    private JPanel panel3;
    private JButton button1;
    private JButton button2;
    private JPanel panel4;
    private JLabel label2;
    private JLabel label3;
    private JPanel panel5;
    private JButton button3;
}
